import api, { type ResponseData } from '../index'

export type CartParams = {
	skuId?: string | number,
	basketCount: number
}
// 添加到购物车
export const postAddCart = (data: CartParams[]) =>
	api.post('customer/api/basket', {
		data,
		header: {
			'Content-Type': 'application/json'
		}
	})

export type CartGoodsItem = {
		basketCount:number
		id:string
		skuId:string
		storeId:string
		userId:string
		prodId:string
		serviceId:string
		deliveryMode:string //支持的配送方式
		productSku:{
			is:string,
			price:number
			productId:string
			productName:string
			skuCoverImg:string
			skuSpec:string
			skuKey:string
			stock:number
			stockSold:number
			
		}
	}

export type CartItem = {
	baskets:Array<CartGoodsItem>,
	store:{
		id:string,
		logo:string,
		name:string
	}
}

// 购物车列表
export const getShoppingCartList = () =>
	api.get<ResponseData<CartItem[]>&{
		invalid:Array<CartGoodsItem>,
		productAll:number
	}>('customer/api/basket/list')
// 编辑购物车商品数量、规格
export const postEditCart = (data: CartParams, id: string | number) =>
	api.put(`customer/api/basket/${id}`, {
		data,
		custom: {
			isLoading: true
		}
	})
// 购物车商品删除
export const postDleCart = (id: string | number) =>
	api.delete(`customer/api/basket/${id}`, {
		custom: {
			isLoading: true
		}
	})
